package com.travel.server.manager.impl.command.question;

import com.travel.common.util.CollectionUtil;
import com.travel.server.manager.dto.request.EmptyRequest;
import com.travel.server.manager.dto.response.question.QueryQuestionEnumResponse;
import com.travel.server.manager.dto.response.question.QueryQuestionEnumResponse.QuestionEnumItem;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.dal.QuestionnaireDal;
import com.travel.server.manager.model.QuestionnaireInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: LiZhenhui
 * @Date: 2018/11/23 17:58
 * @Desc:
 */
@Component
public class QueryQuestionEnumCommand extends AbstractCommand<EmptyRequest, QueryQuestionEnumResponse> {

    @Autowired
    private QuestionnaireDal questionnaireDal;

    @Override
    protected void checkInput(EmptyRequest request) {

    }

    @Override
    public QueryQuestionEnumResponse handle(EmptyRequest request) {
        List<QuestionnaireInfo> list = questionnaireDal.selectByExample(null);
        List<QuestionEnumItem> questionList = new ArrayList<>();
        if(!CollectionUtil.isEmpty(list)){
            for(QuestionnaireInfo questionnaireInfo : list){
                QuestionEnumItem item = new QuestionEnumItem();
                item.setId(questionnaireInfo.getId());
                item.setName(questionnaireInfo.getQuestionnaireName());
                questionList.add(item);
            }
        }
        QueryQuestionEnumResponse response = new QueryQuestionEnumResponse();
        response.setQuestionList(questionList);
        return response;
    }
}
